CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5Widgets REQUIRED)


include_directories(${COMN_DIR}/include)
include_directories(.)

if (MSVC)
	include_directories(${THIRD_PARTY}/stdint)
endif()

include_directories(${LITEPLAYER_DIR}/LitePlayer/include)
include_directories(${THIRD_PARTY}/sqlite/include)
include_directories(${THIRD_PARTY}/xlsx)

link_directories(${PROJECT_ROOT}/lib)
link_directories(${COMN_DIR}/lib)
link_directories(${LITEPLAYER_DIR}/lib)
link_directories(${DIR_FFMPEG_LIB})
link_directories(${THIRD_PARTY}/sqlite/lib)

include_directories(util)
include_directories(${PROJECT_ROOT}/http)

add_definitions(-DXLSX_NO_LIB)

aux_source_directory(. SOURCES)
#aux_source_directory(util SOURCES)


SET(EXECUTABLE_TYPE "WIN32")

if (MSVC)
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /DEBUG")
endif()

set(LIB_PLATFORM ${LIB_PLATFORM} Ws2_32 winmm)


add_executable(RoundPlayer ${EXECUTABLE_TYPE} ${SOURCES} RoundPlayer.qrc RoundPlayer.rc)


target_link_libraries(RoundPlayer
	Qt5::Widgets Qt5::Core
	debug comnd optimized comn
	${LIB_PLATFORM}
	LitePlayer
	sqlite3
	debug xlsxd optimized xlsx
	)


    
set(VERSION_MAJOR "1")
set(VERSION_MINOR "0")
set(VERSION_PATCH "2")

CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
  ${CMAKE_CURRENT_SOURCE_DIR}/version.h
)

    
install(TARGETS RoundPlayer DESTINATION .)

install(FILES ${PROJECT_ROOT}/setup/RoundPlayer.ini DESTINATION .)
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/en.qm DESTINATION .)
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/zh_CN.qm DESTINATION .)


if(WIN32)
	install(DIRECTORY ${LITEPLAYER_DIR}/third_party/ffmpeg/bin/ DESTINATION . FILES_MATCHING PATTERN "*.dll")
	install(FILES ${LITEPLAYER_DIR}/third_party/SDL2-2.0.4/lib/x86/SDL2.dll DESTINATION .)
	
	install(FILES ${THIRD_PARTY}/sqlite/bin/sqlite3.dll DESTINATION .)
	
	install(FILES ${QT_DIR}/bin/Qt5Core.dll DESTINATION .)
	install(FILES ${QT_DIR}/bin/Qt5Gui.dll DESTINATION .)
	install(FILES ${QT_DIR}/bin/Qt5Widgets.dll DESTINATION .)
	install(FILES "${QT_DIR}/plugins/platforms/qwindows.dll" DESTINATION platforms)
	
	install(FILES ${LITEPLAYER_DIR}/bin/LitePlayer.dll DESTINATION .)
	
else()

endif()

set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
include(InstallRequiredSystemLibraries)

#set(CPACK_PACKAGE_DIRECTORY ${PROJECT_ROOT})
set(CPACK_PACKAGE_NAME "RoundPlayer")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "RoundPlayer")
set(CPACK_PACKAGE_VENDOR "www.100wits.com")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})

if(UNIX)
	SET(CPACK_GENERATOR "TGZ")
else()
	SET(CPACK_GENERATOR "ZIP")
endif()

set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/../dist") 
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") 

include(CPack)
